

import java.util.ArrayList;

public class ResponseTimeAnalyzer {

	public static boolean analyze (ArrayList<Task> tasks) {

		//Sort tasks after their priority, 
		//so least priority is last?
		//TODO

		double I;//interference due to preemption
		double R;

		for (int i=0 ; i<tasks.size() ; i++) {
			Task task_i = tasks.get(i);
			I=0;
			
			do {
				R=I+task_i.getComputationTime();

				//Begin Debugging
				int i_computationTime = task_i.getComputationTime();
				//end debugging

				if (R > task_i.getDeadline()) {
					//Not schedulable
					return false;
				}

				//Compute I
				for (int j=1 ; j<i; j++) {

					
						Task task_j = tasks.get(j);
						//I = I + Math.ceil(R/task_j.getPeriod())*task_j.getComputationTime();
						I = Math.ceil(R/task_j.getPeriod())*task_j.getComputationTime();
						
						//begin Debugging
						int computationTime = task_j.getComputationTime();
						int period = task_j.getPeriod();
						double fraction = R/period;
						double ceiledFraction = Math.ceil(fraction);
						double addedToI = ceiledFraction*computationTime;
						//end Debugging

					

				}

			} while (I+task_i.getComputationTime() > R);
		}
		return true;
	}

}

